home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / TURB_VIS / MISC / MISC.PAS < prev   
Pascal/Delphi Source File  |  1990-12-17  |  27KB  |  728 lines

  1. Unit Misc;
  2.  
  3. { Note:  Tab Size = 4 }
  4.  
  5. (* Set conditions to allow for "Extended" type *)
  6. {$N+,E+}
  7.  
  8. (**************************************************************************)
  9. (*                                                                        *)
  10. (*               Library of objects for Turbo Vision  V1.00               *)
  11. (*                                                                        *)
  12. (*               By:   Devin Cook                                         *)
  13. (*                     copyright (c) 1990 MSD                             *)
  14. (*                     Public Domain Object library                       *)
  15. (*                                                                        *)
  16. (*   Object:  TDateView                                                   *)
  17. (*                Same as TClockView, except displays the date            *)
  18. (*                                                                        *)
  19. (*   Object:  TPushButton                                                 *)
  20. (*                Same as TButton, except button "Show" press by keyboard *)
  21. (*                                                                        *)
  22. (*   Object:  TNum_Box                                                    *)
  23. (*                An editable number only entry box - configurable        *)
  24. (*                                                                        *)
  25. (*   Object:  TLinked_Dialog                                              *)
  26. (*                A normal dialog which handles cursor links to other     *)
  27. (*                items                                                   *)
  28. (*                                                                        *)
  29. (*   Func:    FormatDate                                                  *)
  30. (*                Formats a date into a string                            *)
  31. (*                                                                        *)
  32. (**************************************************************************)
  33.  
  34. {$F+,O+,S-,D+}
  35.  
  36. Interface
  37.  
  38. Uses Crt, Dos, Objects, Views, Dialogs, Drivers;
  39.  
  40. (*   Constents for Linked_Dialog   *)
  41.  
  42. Const    DLink_Left        =    1 ;
  43.         DLink_Right        =    2 ;
  44.         DLink_Up        =    3 ;
  45.         DLink_Down        =    4 ;
  46.         DLink_Spare1    =    5 ;
  47.         DLink_Spare2    =    6 ;
  48.  
  49. Type
  50.  
  51. (**************************************************************************)
  52. (*                                                                        *)
  53. (*                        Object: TDateView                               *)
  54. (*                                                                        *)
  55. (*  Desc: TDateView is a static text object of the date, in a formated    *)
  56. (*        string, usually placed on the status or menu lines.             *)
  57. (*                                                                        *)
  58. (*        Format:  Sun  Dec 16, 1990                                      *)
  59. (*                                                                        *)
  60. (*        This format can be altered by changing Function FormatDate.     *)
  61. (*                                                                        *)
  62. (*  Init: Initialization is done by supply a TRect to the INIT method.    *)
  63. (*                                                                        *)
  64. (*  Note: The UPDATE method checks to see if the Day-of-Week value still  *)
  65. (*        matches the system Day-of-Week, and updates it's view if they   *)
  66. (*        don't match.  An occasional call to TDateView.UPDATE will keep  *)
  67. (*        your date indicator up to date.                                 *)
  68. (*                                                                        *)
  69. (**************************************************************************)
  70.  
  71.     PDateView = ^TDateView;
  72.     TDateView = Object(TView)
  73.                     DateStr: string[19];
  74.                     Last_DOW: Word;
  75.                     Constructor Init(var Bounds: TRect);
  76.                     Procedure Draw; virtual;
  77.                     Procedure Update; virtual;
  78.                 End;
  79.  
  80. (**************************************************************************)
  81. (*                                                                        *)
  82. (*                        Object: TPushButton                             *)
  83. (*                                                                        *)
  84. (*  Desc: TPushButton is a TButton except that it indicates being         *)
  85. (*        pressed from the keyboard.                                      *)
  86. (*                                                                        *)
  87. (*  Note: You may wish to adjust with the delay values in the             *)
  88. (*        TPushButton.Press method to suit your taste.                    *)
  89. (*                                                                        *)
  90. (*        See TButton for method descriptions.                            *)
  91. (*                                                                        *)
  92. (**************************************************************************)
  93.  
  94.   PPushButton    =    ^TPushButton;
  95.   TPushButton    =    Object(Tbutton)
  96.                         Procedure Press ;    Virtual ;
  97.                     End;
  98.  
  99. (**************************************************************************)
  100. (*                                                                        *)
  101. (*                        Object: TNum_Box                                *)
  102. (*                                                                        *)
  103. (*  Desc: TInt_Box is a number only input box with an adjustable number   *)
  104. (*        of digits before and after the decimal point.                   *)
  105. (*                                                                        *)
  106. (*        It can be flagged not to accept negative numbers if desired.    *)
  107. (*                                                                        *)
  108. (*  Init: Initialization is done by providing your desired configuration  *)
  109. (*        to TNum_Box.Init.                                               *)
  110. (*                                                                        *)
  111. (*        TNum_Box.Init(                                                  *)
  112. (*            Loc       -     TPoint with location for num                *)
  113. (*            MaxWh     -     Integer with #digits before the decimal     *)
  114. (*                            point                                       *)
  115. (*            MaxDs     -     Integer with #digits after the decimal      *)
  116. (*                            point                                       *)
  117. (*            NegOk     -     Boolean.  True if neg values allowed        *)
  118. (*            Deflt     -     Extended floating point with default value  *)
  119. (*                     )                                                  *)
  120. (*                                                                        *)
  121. (*  Box width =   MaxWh +                                                 *)
  122. (*                MaxDs + 1 ( if MaxDs > 0 ) +                            *)
  123. (*                1 if Negok                                              *)
  124. (*                                                                        *)
  125. (*  To read the value back, simply access the Curr_Val variable for the   *)
  126. (*  TNum_Box.  It is an extended floating point varaible, so you should   *)
  127. (*  convert it to the desired precision.                                  *)
  128. (*                                                                        *)
  129. (*  Note:  A call to TNum_Box.Update_Val "Locks" the edited number into   *)
  130. (*         the curr_val field, loading the default value if no number has *)
  131. (*         been entered.                                                  *)
  132. (*                                                                        *)
  133. (**************************************************************************)
  134.  
  135.     PNum_Box    =    ^TNum_Box;
  136.     TNum_Box    =    Object    ( TView )
  137.                         Max_Whole    :    Integer ;
  138.                         Max_Decs    :    Integer ;
  139.                         Max_Len        :    Integer ;
  140.                         Neg_Ok      :   Boolean ;
  141.                         Default_val    :    Extended ;
  142.                         Num_Str        :    String[24] ;
  143.                         Curr_Val    :    Extended ;
  144.                         Dec_Pos        :    Integer ;
  145.                         First_Char    :    Boolean ;
  146.  
  147.                         Constructor Init( Loc    :    TPoint ;
  148.                                           MaxWh :    Integer ;
  149.                                           MaxDs :    Integer ;
  150.                                           NegOk :     Boolean ;
  151.                                           Dflt    :    Extended );
  152.                         Procedure Draw;    Virtual;
  153.                         Procedure HandleEvent( Var Event:TEvent ); Virtual;
  154.                         Procedure SetState( AState:Word; Enable:Boolean);
  155.                             Virtual;
  156.                         Procedure Add_Digit( Charcode : Char );    Virtual;
  157.                         Procedure Do_Edit( Keycode : Word ); Virtual;
  158.                         Procedure Update_Value;
  159.                     End;
  160.  
  161. (*  Record used by TLinked_Dialog  *)
  162.  
  163.         DLink_Record    =    Record
  164.                                 Item        :    Pointer ;
  165.                                 Left_Link    :    Pointer ;
  166.                                 Right_Link    :    Pointer ;
  167.                                 Up_Link        :    Pointer ;
  168.                                 Down_Link    :    Pointer ;
  169.                                 Spare1_Link    :    Pointer ;
  170.                                 Spare2_Link    :    Pointer ;
  171.                             End;
  172.  
  173. (*  Object for TLinked_Dialog's collection  *)
  174.  
  175.         PLink_Item        =    ^TLink_Item ;
  176.         TLink_Item        =    Object
  177.                                 Item        :    Pointer ;
  178.                                 Pointers    :    Array[1..6] of Pointer ;
  179.                                 Constructor Init( Link_Rec : DLink_Record );
  180.                                 Procedure Add_Link( Link_Direc : Integer ;
  181.                                                     Link : Pointer );
  182.                             End;
  183.  
  184. (*  TLinked_Dialog's collection of links  *)
  185.  
  186.         PLinked_List    =    ^TLinked_List ;
  187.         TLinked_List    =    Object( TCollection )
  188.                                 Function Search( key : Pointer ) : Integer ;
  189.                             End;
  190.  
  191. (**************************************************************************)
  192. (*                                                                        *)
  193. (*                        Object: TLinked_Dialog                          *)
  194. (*                                                                        *)
  195. (*  Desc: TLinked_Dialog is a variation of a standard dialog which        *)
  196. (*        allows for improved cursor movement between items.              *)
  197. (*                                                                        *)
  198. (*        You can define which objects to "Link" to on the right, left,   *)
  199. (*        above and below.  These objects are focused by use of the       *)
  200. (*        cursor keys.                                                    *)
  201. (*                                                                        *)
  202. (*        Two spare links are defined for item use ( such as switching    *)
  203. (*        to a certain box once a button is pressed. )                    *)
  204. (*                                                                        *)
  205. (*  Init: Initialization is identical to TDialog's init.  Refer to the    *)
  206. (*        Turbo Vision manual for details.                                *)
  207. (*                                                                        *)
  208. (*  Inserting an item is identical to a normal TDialog.Insert. When an    *)
  209. (*  item is inserted into a TLinked_Dialog, a record is created for       *)
  210. (*  tracking links.                                                       *)
  211. (*                                                                        *)
  212. (*                             Defining a Link                            *)
  213. (*                                                                        *)
  214. (*  Once you have inserted all items into your dialog, links are created  *)
  215. (*  to other items using TLinked_Dialog.Setlink.                          *)
  216. (*                                                                        *)
  217. (*  TLinked_Dialog.Setlink(                                               *)
  218. (*       P          -    PView or descendant.                             *)
  219. (*                       This is a pointer to the item you wish to add    *)
  220. (*                       the link to.                                     *)
  221. (*       Link_Direc -    Integer with link direction.                     *)
  222. (*                       This should be one of the following constants:   *)
  223. (*                             DLink_Up     :   Up                        *)
  224. (*                             DLink_Down   :   Down                      *)
  225. (*                             DLink_Right  :   Right                     *)
  226. (*                             DLink_Left   :   Left                      *)
  227. (*                             DLink_Spare1 :   Spare 1                   *)
  228. (*                             DLink_Spare2 :   Spare 2                   *)
  229. (*       Link       -    A pointer to the item you want to link to        *)
  230. (*       )                                                                *)
  231. (*                                                                        *)
  232. (*                           Accesing a link                              *)
  233. (*                                                                        *)
  234. (*  Items within a dialog can switch to a linked item by calling:         *)
  235. (*                                                                        *)
  236. (*  TLinked_Dialog.Select_link(                                           *)
  237. (*       Direc      -    Integer with link direction.                     *)
  238. (*       )                                                                *)
  239. (*                                                                        *)
  240. (**************************************************************************)
  241.  
  242.         PLinked_Dialog    =   ^TLinked_Dialog ;
  243.         TLinked_Dialog    =    Object( TDialog )
  244.                                 Link_List    :    TLinked_List ;
  245.                                 Constructor Init(var Bounds: TRect;
  246.                                                  ATitle: TTitleStr);
  247.                                 Procedure Insert(P: PView); Virtual;
  248.                                 Procedure Set_Link( P: PView ;
  249.                                                     Link_Direc : Integer ;
  250.                                                     Link : Pointer );
  251.                                 Procedure HandleEvent( Var Event : TEvent );
  252.                                     Virtual;
  253.                                 Procedure Select_Link( Direc : Integer );
  254.                             End;
  255.  
  256.  
  257. (**************************************************************************)
  258. (*                                                                        *)
  259. (*                      Function: FormatDate                              *)
  260. (*                                                                        *)
  261. (*  Desc:  The format date function used by TDateView, made public for    *)
  262. (*         other possible uses.                                           *)
  263. (*                                                                        *)
  264. (**************************************************************************)
  265.  
  266. Function FormatDate( Year , Month , Day , DOW : Word ): String;
  267.  
  268. Implementation
  269.  
  270. (**************************************************************************)
  271. (*                                                                        *)
  272. (*                        Object: TDateView                               *)
  273. (*                                                                        *)
  274. (**************************************************************************)
  275.  
  276. Constructor TDateView.Init(var Bounds: TRect);
  277. Begin
  278.     TView.Init(Bounds);
  279.     DateStr := '';
  280.     LAST_DOW := 8 ;     (*  Force an update!  *)
  281. End;
  282.  
  283.  
  284. (* Draw the TDateView object *)
  285.  
  286. Procedure TDateView.Draw;
  287. Var
  288.     B: TDrawBuffer;
  289.     C: Byte;
  290. Begin
  291.     C := GetColor(2);
  292.     MoveChar(B, ' ', C, Size.X);
  293.     MoveStr(B, DateStr, C);
  294.     WriteLine(0, 0, Size.X, 1, B);
  295. End;
  296.  
  297. (* Verify the TDateView object is up to date *)
  298. (* Redisplaying it if it needs updating      *)
  299.  
  300. Procedure TDateView.Update;
  301. Var Year, Month, Day, DOW : word;
  302. Begin
  303.     GetDate( Year , Month , Day , Dow );
  304.     If (DOW <> LAST_DOW) then
  305.     Begin
  306.         DateStr := FormatDate( Year , Month , Day , DOW );
  307.         DrawView;
  308.         LAST_DOW := DOW ;
  309.     End;
  310. End;
  311.  
  312. (**************************************************************************)
  313. (*                                                                        *)
  314. (*                        Object: TPushButton                             *)
  315. (*                                                                        *)
  316. (**************************************************************************)
  317.  
  318. Procedure TPushButton.Press;
  319. Begin
  320.     DrawState(TRUE);    (*  Draw Button "Pressed"  *)
  321.     Delay(150);
  322.     DrawState(FALSE);    (*  Draw Button "Released" *)
  323.     Delay(50);
  324.     TButton.Press;
  325. End;
  326.  
  327. (**************************************************************************)
  328. (*                                                                        *)
  329. (*                        Object: TNum_Box                                *)
  330. (*                                                                        *)
  331. (**************************************************************************)
  332.  
  333. Constructor TNum_Box.Init( Loc : TPoint ; MaxWh, MaxDs : Integer ;
  334.                            NegOk : Boolean ;  Dflt : Extended );
  335. Var    R        :    TRect ;
  336.     X        :    Integer ;
  337.     Wrk_Str :    String ;
  338.  
  339. Begin
  340.  
  341.     Wrk_Str := '' ;
  342.     If ( NegOk ) then
  343.         Wrk_Str := ' ' ;
  344.     For X := 1 to MaxWh do
  345.         Wrk_Str := Wrk_Str + ' ' ;
  346.  
  347.     If ( MaxDs > 0 ) then
  348.     Begin
  349.         Wrk_Str := Wrk_Str + '.';
  350.         For X := 1 to MaxDs do
  351.             Wrk_Str := Wrk_Str + ' ' ;
  352.     End;
  353.     R.Assign( Loc.X , Loc.Y , Loc.X + Length( Wrk_Str ) , Loc.Y + 1 );
  354.     TView.Init( R ) ;
  355.  
  356.     Num_Str := Wrk_Str ;
  357.  
  358.     Neg_Ok := NegOk ;
  359.     Max_Whole := MaxWh ;
  360.     Max_Decs := MaxDs ;
  361.  
  362.     Max_Len := Length( Num_Str );
  363.  
  364.     Options := Options OR ofSelectable ;
  365.  
  366.     Default_Val := Dflt ;
  367.     Curr_Val := Dflt ;
  368.     Dec_Pos := Pos( '.' , Num_Str );
  369.  
  370.     If ( Dec_Pos < 1 ) then
  371.         Dec_Pos := Max_Len + 1 ;
  372.  
  373.  
  374.     Cursor.X := Dec_Pos - 2;
  375.  
  376.     First_Char := True ;
  377.     ShowCursor;
  378. End;
  379.  
  380. (*  Draw the TNum_Box on the view.  *)
  381. (*  Color depends on the state of   *)
  382. (*  the object.                     *)
  383.  
  384. Procedure TNum_Box.Draw;
  385. Var    Buff : TDrawBuffer ;
  386.     Colr : Word;
  387. Begin
  388.     Colr := GetColor(19);
  389.     If GetState(sfFocused) then
  390.         If First_Char then
  391.             Colr := GetColor(20)
  392.         else
  393.             Colr := GetColor(22);
  394.  
  395.     MoveChar( Buff,' ',Colr, Size.X);
  396.     MoveStr( Buff,Num_Str,0);
  397.     Writeline(0,0,Size.X,1,Buff);
  398.  
  399. End;
  400.  
  401. (*  Updated SetState to watch for changes in the  *)
  402. (*  selected and focused flags.                   *)
  403.  
  404. Procedure TNum_Box.SetState(AState: Word; Enable: Boolean);
  405. Begin
  406.     TView.SetState(AState, Enable);
  407.     If ( AState = sfFocused ) then
  408.         Draw ;
  409.     If ( AState = sfFocused ) And ( Enable ) then
  410.         First_Char := TRUE ;
  411. End;
  412.  
  413. (*  HandleEvent, routing keystrokes  *)
  414.  
  415. Procedure TNum_Box.HandleEvent( Var Event : TEvent );
  416. Var    NextCmd: TEvent;
  417.     test:PEvent;
  418. Begin
  419.     TView.HandleEvent( Event );
  420.     If Event.What = evKeydown then
  421.     Begin
  422.         Case ( Event.Charcode ) of
  423.             #00        :   Begin
  424.                         End;
  425.             #08        :    Begin
  426.                             Do_Edit( Event.keyCode );
  427.                             ClearEvent( Event );
  428.                         End;
  429.             #13        :    Begin
  430.                             ClearEvent( Event );
  431.                             Update_Value ;
  432.                         End;
  433.             '0'..'9':    Begin
  434.                             Add_Digit( Event.Charcode );
  435.                             ClearEvent( Event );
  436.                         End;
  437.             '.','-':    Begin
  438.                             Add_Digit( Event.Charcode );
  439.                             ClearEvent( Event );
  440.                         End;
  441.             End;
  442.     End;
  443. End;
  444.  
  445. (*  Perform normal charector addition to the number string  *)
  446.  
  447. Procedure TNum_Box.Add_Digit( Charcode : Char );
  448. Var    X            :    Integer ;
  449.     First_Dig    :    Integer ;
  450. Begin
  451.  
  452.     If ( First_Char ) then
  453.     Begin
  454.         For X := 1 to Length( Num_Str ) do
  455.             If (Num_Str[X]<>'.') then
  456.                 Num_Str[X]:=' ';
  457.  
  458.         First_Char := False ;
  459.         Cursor.X := Dec_Pos - 2;
  460.         ShowCursor;
  461.     End;
  462.  
  463.     If Neg_Ok then
  464.         First_Dig := 2
  465.     else
  466.         First_Dig := 1;
  467.  
  468.     If ( Cursor.X < Dec_Pos ) then
  469.     Case ( Charcode ) of
  470.         '0'..'9'    :    If Not( Num_Str[ First_Dig ] IN ['0'..'9']) then
  471.                         Begin
  472.                             For X := 1 to Cursor.X do
  473.                                 Num_Str[X] := Num_Str[X+1] ;
  474.                             Num_Str[ Cursor.X + 1 ] := Charcode ;
  475.                         End;
  476.         '-'            :    Begin
  477.                             If (Neg_Ok) then
  478.                             Begin
  479.                                 if (Num_Str[ Cursor.X + 1 ] = ' ') then
  480.                                     Num_Str[ Cursor.X + 1 ] := '-'
  481.                             End;
  482.                         End;
  483.         '.'            :    Begin
  484.                             If (Max_Decs>0) and ( Cursor.X < Dec_Pos ) then
  485.                             Begin
  486.                                 Cursor.X := Dec_Pos ;
  487.                                 ShowCursor;
  488.                             End;
  489.                         End;
  490.     End
  491.     else
  492.     Case ( Charcode ) of
  493.         '0'..'9'    :    Begin
  494.                             If ( Cursor.X < ( Max_Len - 1 )) then
  495.                             Begin
  496.                                 Num_Str[Cursor.X+1] := Charcode ;
  497.                                 Inc( Cursor.X );
  498.                                 ShowCursor;
  499.                             End
  500.                             else
  501.                                 if Num_Str[Cursor.X+1] = ' ' then
  502.                                     Num_Str[Cursor.X+1] := Charcode ;
  503.                         End;
  504.     End;
  505.  
  506.     Draw;
  507. End;
  508.  
  509. (*  Perform any editing on the number string  *)
  510. (*  ( Only the <Backspace> key is currently   *)
  511. (*  supported ).                              *)
  512.  
  513. Procedure TNum_Box.Do_Edit( Keycode : Word );
  514. Var    X            :    Integer ;
  515. Begin
  516.     First_Char := False ;
  517.     If ( Dec_Pos = 0 ) or ( Cursor.X < Dec_Pos ) then
  518.     Begin
  519.         If (Keycode = kbBack) then
  520.         Begin
  521.             For X := Cursor.X+1 downto 2 do
  522.                 Num_Str[X] := Num_Str[X-1] ;
  523.             Num_Str[ 1 ] := ' ' ;
  524.         End;
  525.     End
  526.     else
  527.     Begin
  528.         If (Keycode = kbBack) then
  529.         Begin
  530.             If Num_Str[Cursor.X+1] = ' ' then
  531.             Begin
  532.                 Dec( Cursor.X );
  533.                 Num_Str[Cursor.X+1] := ' ';
  534.             End
  535.             else
  536.                 Num_Str[Cursor.X+1] := ' ';
  537.  
  538.             If Num_Str[ Cursor.X ] = '.' then
  539.                 Cursor.X := Cursor.X - 2 ;
  540.             ShowCursor;
  541.         End;
  542.     End;
  543.  
  544.     Draw;
  545. End;
  546.  
  547. (* "Lock" the number string value in the box.     *)
  548. (* Use the default value if no number is present. *)
  549.  
  550. Procedure TNum_Box.Update_Value;
  551. Var Code    :    Integer ;
  552.     Work_str:    String[24];
  553. Begin
  554.     Work_Str := Num_Str ;
  555.     While (( Length( Work_Str )>0 ) and ( Work_Str[Length( Work_Str )] IN ['.',' '])) do
  556.         Work_Str := Copy( Work_Str , 1 , length( Work_Str ) -1 );
  557.  
  558.     Code := 0 ;
  559.  
  560.     If ( Work_Str = '' ) then
  561.         Curr_Val := Default_Val
  562.     else
  563.         Val( Work_Str, Curr_Val , Code );
  564.     Str( Curr_Val:Max_Len:Max_Decs , Num_Str );
  565.  
  566.     Cursor.X := Max_Len - 1 ;
  567.     First_Char := True ;
  568.     Draw;
  569. End;
  570.  
  571. (**************************************************************************)
  572. (*                                                                        *)
  573. (*                        Object: TLink_Item                              *)
  574. (*                                                                        *)
  575. (*                 Used by TLinked_Dialog to track links                  *)
  576. (*                                                                        *)
  577. (**************************************************************************)
  578.  
  579. Constructor TLink_Item.Init( Link_Rec : DLink_Record );
  580. Begin
  581.     Item := Link_Rec.Item ;
  582.     With Link_Rec do
  583.     Begin
  584.         Pointers[DLink_Left]    := Left_Link;
  585.         Pointers[DLink_Right]    := Right_Link;
  586.         Pointers[DLink_Up]        := Up_Link;
  587.         Pointers[DLink_Down]     := Down_Link;
  588.         Pointers[DLink_Spare1]    := Spare1_Link;
  589.         Pointers[DLink_Spare2]    := Spare2_Link;
  590.     End;
  591. End;
  592.  
  593. Procedure TLink_Item.Add_Link( Link_Direc : Integer ; Link : Pointer );
  594. Begin
  595.     Pointers[ Link_Direc ] := Link ;
  596. End;
  597.  
  598. (**************************************************************************)
  599. (*                                                                        *)
  600. (*                        Object: TLink_List                              *)
  601. (*                                                                        *)
  602. (*                 Used by TLinked_Dialog to track links                  *)
  603. (*                                                                        *)
  604. (**************************************************************************)
  605.  
  606. Function TLinked_List.Search( Key : Pointer ) : Integer ;
  607. Var    X : Integer ;
  608.     Found : Boolean ;
  609.     Linked_Item : PLink_Item ;
  610. Begin
  611.     Search := -1 ;
  612.     Found := False ;
  613.     X := 0 ;
  614.     While ( X < Count ) AND ( NOT FOUND ) do
  615.     Begin
  616.         Linked_Item := at( X );
  617.         Found := Linked_Item^.Item = Key ;
  618.         X := X + 1 ;
  619.     End;
  620.  
  621.     If ( Found ) then
  622.         Search := X - 1 ;
  623. End;
  624.  
  625. (**************************************************************************)
  626. (*                                                                        *)
  627. (*                        Object: TLinked_Dialog                          *)
  628. (*                                                                        *)
  629. (**************************************************************************)
  630.  
  631. Constructor TLinked_Dialog.Init(var Bounds: TRect; ATitle: TTitleStr);
  632. Begin
  633.     TDialog.Init( Bounds , ATitle );
  634.     Link_List.Init(10, 5);
  635. End;
  636.  
  637. Procedure TLinked_Dialog.Insert(P: PView);
  638. Var    Linked_Item : PLink_Item ;
  639.     Blank_Rec : DLink_Record ;
  640. Begin
  641.     With Blank_Rec do
  642.     Begin
  643.         Item := P ;
  644.         Left_Link     := Nil ;
  645.         Right_Link    := Nil ;
  646.         Up_Link        := Nil ;
  647.         Down_Link    := Nil ;
  648.         Spare1_Link    := Nil ;
  649.         Spare2_Link := Nil ;
  650.     End;
  651.     Linked_Item := New( PLink_Item , Init( Blank_Rec ) );
  652.     TDialog.Insert( P );
  653.     Link_List.Insert( Linked_Item );
  654. End;
  655.  
  656. Procedure TLinked_Dialog.Set_Link(P:PView;Link_Direc:Integer;Link:Pointer);
  657. Var    Linked_Item : PLink_Item ;
  658.     X : Integer ;
  659. Begin
  660.     X := Link_List.Search( P );
  661.     If ( X < 0 ) then
  662.         Exit ;
  663.     Linked_Item := Link_List.at( X );
  664.     Linked_Item^.Pointers[ Link_Direc ] := Link ;
  665. End;
  666.  
  667. Procedure TLinked_Dialog.Select_Link( Direc : Integer );
  668. Var    X        : Integer ;
  669.     LL_Item    : PLink_Item ;
  670.     Item    : PView ;
  671. Begin
  672.     X := Link_List.Search( Current );
  673.     LL_Item := Link_List.at(X);
  674.     Item := LL_Item^.Pointers[ Direc ];
  675.     If ( Item <> Nil ) then
  676.         Item^.Select ;
  677. End;
  678.  
  679. Procedure TLinked_Dialog.HandleEvent( Var Event : TEvent );
  680. Var    X        : Integer ;
  681.     LL_Item    : PLink_Item ;
  682.     Item    : PView ;
  683. Begin
  684.     TDialog.HandleEvent( Event );
  685.  
  686.     If ( Event.What = evKeydown ) then
  687.         Case Event.keycode of
  688.             kbUp    :    Begin
  689.                             Select_Link( DLink_Up );
  690.                             ClearEvent( Event );
  691.                         End;
  692.             kbDown    :    Begin
  693.                             Select_Link( DLink_Down );
  694.                             ClearEvent( Event );
  695.                         End;
  696.             kbRight    :    Begin
  697.                             Select_Link( DLink_Right );
  698.                             ClearEvent( Event );
  699.                         End;
  700.             kbLeft    :    Begin
  701.                             Select_Link( DLink_Left );
  702.                             ClearEvent( Event );
  703.                         End;
  704.         End;
  705. End;
  706.  
  707. (**************************************************************************)
  708. (*                                                                        *)
  709. (*                      Function: FormatDate                              *)
  710. (*                                                                        *)
  711. (**************************************************************************)
  712.  
  713. Function FormatDate( Year , Month , Day , DOW : Word ): String;
  714. Const
  715.     DAYS : Array[0..6] of String = ( 'Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  716.     MONTHS : Array[1..12] of String = ( 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
  717. Var Work1,Work2 : String[4] ;
  718. Begin
  719.     Str( Day,Work1 );
  720.     If ( Day < 10 ) then
  721.     Work1 := '0' + Work1 ;
  722.     Str( Year,Work2 );
  723.     FormatDate := DAYS[DOW]+'  '+MONTHS[Month]+' '+Work1+', '+Work2;
  724. End;
  725.  
  726. Begin
  727. end.
  728.